package com.example.commentserver.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.commentserver.entity.Talk;
import com.example.commentserver.manager.TalkManager;
import com.example.commentserver.params.PageTalkParams;
import com.example.commentserver.params.TalkParams;
import com.example.commentserver.vo.TalkListVO;
import com.example.commentserver.vo.TalkVO;
import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.utils.BeanCopyUtils;
import com.example.userserver.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TalkService {
    @Autowired
    private TalkManager talkManager;
    public List<TalkVO> talkDetail(TalkParams talkParams){
        return talkManager.talkDetail(talkParams);
    }

    public void deleteTalk(String id) {
        talkManager.deleteTalk(id);
    }

    public Result updateTalk(TalkParams talkParams) {
        Talk talk = new Talk();
        talk.setReaded(1);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("post_id", talkParams.getPostId());
        queryWrapper.eq("get_id", talkParams.getGetId());
        talkManager.updateTalk(talk, queryWrapper);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    public Result insertTalk(TalkParams talkParams) {
        Talk talk = new Talk();
        BeanCopyUtils.copyPropertiesIgnoreNull(talkParams, talk);
        talkManager.insertTalk(talk);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    public List<TalkListVO> talkList(PageTalkParams pageTalkParams) {
        return talkManager.talkList(pageTalkParams);
    }
}
